package com.wizz.trade.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.information.dto.page.OrdersPageDto;
import com.wizz.trade.information.entity.Orders;
import com.wizz.trade.information.mapper.OrdersMapper;
import com.wizz.trade.information.service.OrdersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.common.PageVo;
import com.wizz.trade.util.PageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 订单模式表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-02 04:26:06
 */
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {

    @Resource
    private OrdersMapper ordersMapper;


    @Override
    public void addOrders(Orders orders) {
        ordersMapper.insert(orders);
    }

    @Override
    public void updateOrders(Orders orders) {
        ordersMapper.updateById(orders);
    }

    @Override
    public void deleteOrders(Integer id) {
        ordersMapper.deleteById(id);
    }

    @Override
    public PageVo<Orders> getPage(OrdersPageDto ordersPageDto) {
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(ordersPageDto.getMode()), Orders::getMode, ordersPageDto.getMode());
        IPage<Orders> page = ordersMapper.selectPage(PageUtil.initPage(ordersPageDto), queryWrapper);
        return new PageVo<>(page);
    }

    @Override
    public List<Orders> getAll() {
        return ordersMapper.selectList(null);
    }

    @Override
    public List<Map<Integer, String>> getNames() {
        return ordersMapper.getNames();
    }

    @Override
    public List<Map<Integer, String>> getOptions() {
        return ordersMapper.getOptions();
    }

}
